import { encodeSearchParams } from "@/utils";
import { requestCustom, requestUpload } from "./request";
import type { PageParams, PageResponse } from "./types";
import { CHECK_TYPE_CATEGORY, CHECK_TYPE_ALIAS } from "@/enum/check";

export function getTimeListApi(platform: string, category: string) {
  return (data?: any, params?: PageParams) => {
    let url = `/cake/supply/bill/billTimelist?${encodeSearchParams({
      ...params,
      type: platform,
    })}`;
    if (CHECK_TYPE_CATEGORY.ACCOUNT == category) {
      url = `/${platform}/cake/settlement/bill/billTimelist?${encodeSearchParams(
        params
      )}`;
    }
    return requestCustom({
      url,
      method: "GET",
      data,
    });
  };
}

export function getSecondListApi(platform: string, category: string) {
  return (data?: any, params?: PageParams) => {
    let url = `/cake/supply/bill/getPoiListByTime?${encodeSearchParams({
      ...params,
      type: platform,
    })}`;

    if (
      CHECK_TYPE_CATEGORY.ACCOUNT == category &&
      platform == CHECK_TYPE_ALIAS.MEITUAN
    ) {
      url = `/${platform}/cake/settlement/bill/listByMobile?${encodeSearchParams(
        params
      )}`;
    } else if (CHECK_TYPE_CATEGORY.ACCOUNT == category) {
      url = `/${platform}/cake/settlement/bill/getPoiListByTime?${encodeSearchParams(
        params
      )}`;
    }
    return requestCustom({
      url,
      method: "GET",
      data,
    });
  };
}

export function getThirdListApi(platform: string, category: string) {
  return (
    params: { [keyName: string]: any },
    pageParams: Record<string, any>
  ) => {
    const { id } = params;
    let url = `/cake/supply/bill/listByMobile?${encodeSearchParams({
      type: platform,
      ...params,
      ...pageParams,
    })}`;

    if (
      CHECK_TYPE_CATEGORY.ACCOUNT == category &&
      platform == CHECK_TYPE_ALIAS.MEITUAN
    ) {
      url = `/${platform}/cake/settlement/bill/${id}`;
    } else if (CHECK_TYPE_CATEGORY.ACCOUNT == category) {
      url = `/${platform}/cake/settlement/bill/listByMobile?${encodeSearchParams(
        {
          ...params,
          ...pageParams,
        }
      )}`;
    }
    return requestCustom({
      url,
      method: "GET",
    });
  };
}
